package com.habdqn.studentmanager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.habdqn.studentmanager.bean.SysMenu;
import com.habdqn.studentmanager.bean.Teacher;
import com.habdqn.studentmanager.exception.StudentException;
import com.habdqn.studentmanager.service.SystemService;
import com.habdqn.studentmanager.util.ProjectUtil;

/**
 * @author Administrator
 * 
 *         2017年5月15日
 * 
 */
@Controller
public class IndexController {

    @Resource
    private SystemService systemService;

    /**
     * 首页
     * 
     * @return
     */
    @RequestMapping("/")
    public String index(Model model) {

        SysMenu menu = SysMenu.makeMenu(0, null, null, null, null);
        List<SysMenu> menus = null;

        try {
            menus = systemService.findMenuList(menu);
        }
        catch (StudentException e) {
            model.addAttribute("msg", e.getMessage());
            return "error";
        }

        Teacher current = ProjectUtil.getCurrentUser();
        model.addAttribute("current", current);
        model.addAttribute("menus", menus);
        return "index";
    }

    /**
     * 跳转至登陆页面
     * 
     * @return
     */
    @RequestMapping("/login")
    public String login() {

        return "login";
    }

    /**
     * 跳转至欢迎界面
     * 
     * @return
     */
    @RequestMapping("/index/welcome")
    public String welcome() {

        return "welcome";
    }
}
